#!/bin/sh

QUERYSTRING="${1}"

maximumissue="$(GH_FORCE_TTY=1 gh issue list -S Intel | grep Showing | cut -f 4 -d " ")"
printf "Fetching issues... ${maximumissue} available\n"
printf "Getting list of issues to sync... 'intel in:title ${QUERYSTRING}'\n"
gh issue list -S "intel in:title ${QUERYSTRING}" -L "${maximumissue}" | while read issueid _
do
	gh issue view "${issueid}" --json title,body,labels,author,number,createdAt,closed >"intel/LM${issueid}.json"
done
gh issue list -S "intel in:title ${QUERYSTRING} is:closed" | while read issueid _
do
	gh issue view "${issueid}" --json title,body,labels,author,number,createdAt,closed >"intel/LM${issueid}.json"
done
